package com.example.shop.controller;

import com.example.shop.entity.Reviews;
import com.example.shop.service.ReviewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName ReviewsController
 * @Description TODO
 * @Author 萍
 * @Date 2025/3/26 10:27
 */
@RestController
@RequestMapping("/api/reviews")
public class ReviewsController {

    @Autowired
    private ReviewsService reviewsService;

    /**
     * 通过ID查询单条数据
     *
     * @param reviewid 主键
     * @return 实例对象
     */
    @GetMapping("/{reviewid}")
    public Reviews queryById(@PathVariable Integer reviewid) {
        return reviewsService.queryById(reviewid);
    }

    /**
     * 新增数据
     *
     * @param reviews 实例对象
     * @return 实例对象
     */
    @PostMapping
    public Reviews insert(@RequestBody Reviews reviews) {
        return reviewsService.insert(reviews);
    }

    /**
     * 修改数据
     *
     * @param reviews 实例对象
     * @return 实例对象
     */
    @PutMapping
    public Reviews update(@RequestBody Reviews reviews) {
        return reviewsService.update(reviews);
    }

    /**
     * 通过主键删除数据
     *
     * @param reviewid 主键
     * @return 是否成功
     */
    @DeleteMapping("/{reviewid}")
    public boolean deleteById(@PathVariable Integer reviewid) {
        return reviewsService.deleteById(reviewid);
    }

    @GetMapping
    public List<Reviews> queryAll() {
        return reviewsService.queryAll();
    }
}